using Gj;
using UnityEngine.UI;

public class ProgressTextHelper : NodeHelper
{
    public bool size;
    private Text _Text;

    private int totalSize;

    private Text Text
    {
        get
        {
            if (_Text == null) _Text = GetComponent<Text>();
            return _Text;
        }
    }

    protected override BindDataType bindDataType => BindDataType.Int;

    public void SetProgress(float f)
    {
        if (size)
            Text.text = string.Format("{0} / {1} {2}", GetSizeString(totalSize * f), GetSizeString(totalSize),
                totalSize);
        else
            Text.text = f + "%";
    }

    protected override void BindData(int i)
    {
        totalSize = i;
        Text.text = string.Format("{0} / {1}", GetSizeString(0), GetSizeString(totalSize));
    }

    private string GetSizeString(float s)
    {
        return string.Format("{0}MB", (float)(int)(s / 1024 / 1024 * 100) / 100);
    }
}